package top.kindaries.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import top.kindaries.mapper.UserMapper;
import top.kindaries.model.Action;
import top.kindaries.model.User;
import top.kindaries.service.UserService;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by Administrator on 2017/8/16.
 */
@Service
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;


    @Override
    public User getUserByName(String userName) {
        return userMapper.selUserByName(userName);
    }

    @Override
    public User login(User user) {
        return userMapper.selUserByLogin(user);
    }

    @Override
    public PageInfo<User> getUser(User user) {
        PageHelper.startPage(user.getPageNum(), user.getPageSize(), user.getOrderBy());
        List<User> userList = userMapper.selUserByKey(user);
        return new PageInfo<>(userList);
    }

    @Override
    public boolean addUser(User user) {
        return userMapper.insUser(user) == 1;
    }

    @Override
    public boolean editUser(User user) {
        return userMapper.updUser(user) == 1;
    }

    @Override
    public Boolean removeUser(Integer[] ids) {
        return userMapper.delUser(ids) == ids.length;
    }

    @Override
    public List<Action> getActionByUserId(Integer userId) {
        return userMapper.selActionByUserId(userId);
    }

}